package resources

import (
	"log"

	"github.com/xi3/qshop/Godeps/_workspace/src/github.com/qor/qor"
	"github.com/xi3/qshop/Godeps/_workspace/src/github.com/qor/qor/admin"
	"github.com/xi3/qshop/models"
)

func userRegister(adm *admin.Admin) {
	user := adm.AddResource(&models.User{}, &admin.Config{Menu: []string{"User Management"}})

	user.Meta(&admin.Meta{
		Name:       "Role",
		Label:      "Role",
		Type:       "select_one",
		Collection: []string{"owner", "administrator", "customer"},
		Valuer: func(value interface{}, context *qor.Context) interface{} {
			if value == nil {
				log.Println("null value")
				return nil
			}
			user := value.(*models.User)
			log.Println("user", user.Role)
			return user.Role
		},
	})

	user.IndexAttrs("ID", "Mobile", "Name", "Role")
	user.NewAttrs("Mobile", "Name", "Role")
	user.EditAttrs("Mobile", "Name", "Role")

	log.Println("user resosurce registered to admin")
}
